package com.opticon.vaadinR.ui.panel;

import com.opticon.vaadinR.interfaces.DashBoardManager;
import com.opticon.vaadinR.ui.demo.DensityInputPanel;
import com.vaadin.Application;
import com.vaadin.ui.Component;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.VerticalLayout;
import org.apache.log4j.Logger;

/**
 * This class is a
 */
public class DashboardPanel extends VerticalLayout implements DashBoardManager, TabSheet.SelectedTabChangeListener, TabSheet.CloseHandler {
    private static Logger logger = Logger.getLogger(DensityInputPanel.class);

    public TabSheet iTabSheet;
    private final Application iApplication;


    public DashboardPanel(Application aApplication) {
        iApplication = aApplication;

        setSpacing(true);
        setSizeFull();
        iTabSheet = new TabSheet();


        iTabSheet.addListener(this);
        iTabSheet.setCloseHandler(this);

        this.addComponent(iTabSheet);
    }


    public void selectedTabChange(TabSheet.SelectedTabChangeEvent event) {
        TabSheet tabsheet = event.getTabSheet();
        TabSheet.Tab tab = tabsheet.getTab(tabsheet.getSelectedTab());
        if (tab != null && getWindow() != null) {
            getWindow().showNotification("Selected tab: " + tab.getCaption());
        }
    }

    public void onTabClose(TabSheet tabsheet, Component tabContent) {
        getWindow().showNotification(
                "Closed tab: " + tabsheet.getTab(tabContent).getCaption());
        tabsheet.removeComponent(tabContent);
    }


    public void removeAllTabs() {
        iTabSheet.removeAllComponents();
    }

    public void addTab(Component aComponent) {
        iTabSheet.addComponent(aComponent);
    }
}
